import 'package:flame/collisions.dart';
import 'package:flame/components.dart';
import 'package:flutter/material.dart';

class Line extends PositionComponent with CollisionCallbacks{
  double lineWidth;

  Line({
    required this.lineWidth,
    required Vector2 position,
  }) : super(
          position: position,
          size: Vector2(lineWidth, 2),
          anchor: Anchor.center,
        );
  final Paint paint = Paint()
    ..color = Colors.white
    ..style = PaintingStyle.stroke
    ..strokeWidth = 1;

  @override
  void render(Canvas canvas) {
    super.render(canvas);
    canvas.drawLine(Offset.zero, Offset(width, 0), paint);
  }
  late ShapeHitbox shapeHitbox;

  @override
  Future<void> onLoad() async{
    shapeHitbox = RectangleHitbox();
    // shapeHitbox.debugMode = true;
    add(shapeHitbox);
  }

  final collisionColor  =Colors.yellow;

  @override
  void onCollisionStart(
      Set<Vector2> intersectionPoints, PositionComponent other) {
    super.onCollisionStart(intersectionPoints, other);
    paint.color = collisionColor;
  }

  @override
  void onCollisionEnd(PositionComponent other) {
    super.onCollisionEnd(other);
    paint.color = Colors.white;
  }
}
